const log4js = require('log4js');
var path = require('path');
const config = require("../config/config");
const log_dir=config.log_dir;

log4js.configure({
    appenders: {
        // file: {
        //   type: 'file',
        //   filename: path.join(log_dir,'file.log') ,
        //   maxLogSize: 10 * 1024 * 1024, // = 10Mb
        //   backups: 5, // keep five backup files
        //   compress: true, // compress the backups
        //   encoding: 'utf-8',
        //   mode: 0o0640,
        //   flags: 'w+'
        // },
        dateFile: {
          type: 'dateFile',
          filename: path.join(log_dir,'file') ,
          pattern: 'yyyy-MM-dd.log',
          alwaysIncludePattern: true,
          compress: true
        },
        out: {
          type: 'stdout'
        }
      },
      categories: {
        default: { appenders: ['dateFile', 'out'], level: 'trace' }
      }
});

const logger = log4js.getLogger('taobao');
const httpLog = log4js.getLogger('http');
const httpLogger = log4js.connectLogger(httpLog, { level: 'WARN' });

module.exports = {logger,httpLogger};